//双向链表 
#include<stdio.h>
#include<stdlib.h>
struct Node {//定义结构体 
    int data;//节点数据 
    struct Node* next;//下一节点指针 
    struct Node* prev;//上一节点指针 
};
struct Node* createNode(int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));//创造新的节点 
    newNode->data = data;//将数据储存其中 
    newNode->next = NULL;//后指针初始化为 NULL
    newNode->prev = NULL;//前指针初始化为 NULL
    return newNode;
}
void insertNode(struct Node** head, int data) {
    struct Node* newNode = createNode(data);
    if (*head == NULL) {
        *head = newNode;//新节点 
    } 
	else {
        struct Node* temp = *head;
        while (temp->next != NULL) {
            temp = temp->next;
        }//链表末尾插入新的节点 
        temp->next = newNode;
        newNode->prev = temp;//更新两指针 
    }
}
void printList(struct Node* head) {
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;//打印链表中的所有数据 
    }
    printf("\n");
}
int main() {
    struct Node* head = NULL;//创建空链表 
    insertNode(&head, 1);
    insertNode(&head, 2);
    insertNode(&head, 3);//插入三个节点 
    printList(head);//打印链表 
    return 0;
}